package com.example.cloudindex.web;

import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
public class MQAction {

    @Resource
    RabbitTemplate rabbitTemplate;

    //消费者
    @RabbitListener(queuesToDeclare = @Queue("simple.queue"))
    public void oneToOne(String msg){
        System.out.println("msg = " + msg);
    }
    //生产者
    @RequestMapping("sendOndeToOne")
    public String sendOndeToOne(String msg){
        rabbitTemplate.convertAndSend(
                "simple.queue",msg);
        return "一对一消息发送成功";
    }
}
